"""
编写一个函数，传入一个指定目录 （目录中有若干文本文件）
执行这个函数，将目录中文件合并为一个大文件。
合并后文件叫 union.txt
"""
import os


def make_file_path(dir_source_path, file_name):
    if dir_source_path[-1] == '/':
        return dir_source_path + file_name
    else:
        return dir_source_path + "/" + file_name


def union(dir_source_path: str):
    with open(make_file_path(dir_source_path, "union.txt"), 'wb') as file_target:
        for file_name in os.listdir(dir_source_path):
            with open(make_file_path(dir_source_path, file_name), 'rb') as file_source:
                while True:
                    data = file_source.read(1024)
                    if not data:
                        break
                    file_target.write(data)
                    # file_target.write(b'\n')


if __name__ == '__main__':
    dir_source_path = input("请输入目录:")
    union(dir_source_path)
